package com.demo.hadoop;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;

/**
 * 计算出每个地址的访问数量
 *
 * @author lee9213@163.com
 * @version 1.0
 * @date 2017/3/22 14:37
 */
public class AccessProcessReduce extends MapReduceBase implements Reducer<Text, Text, Text, Text> {
    @Override
    public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> outputCollector, Reporter reporter) throws IOException {
        long count = 0;//总计数器
        while (values.hasNext()) {
            String valuetemp = values.next().toString();
            long temp = Long.parseLong(valuetemp);
            count += temp;
        }
        outputCollector.collect(key, new Text(count + ""));
    }
}
